package com.xaicode.learn.java.multithreadarch.ch1;

/**
 * @author Locker cjxia@isoftstone.com
 * @version 1.0
 */
public class TicketWindow {

    public static void main(String[] args) {
        TW tw1 = new TW("1");
        tw1.start();
        TW tw2 = new TW("2");
        tw2.start();
        TW tw3 = new TW("3");
        tw3.start();
        TW tw4 = new TW("4");
        tw4.start();
    }

    static class TW extends Thread {
        private final String name;
        private static final int MAX = 50;

        // 无论类被实例化多少次，只要保证字段唯一即可
        private static int index = 1;

        public TW(String name) {
            this.name = name;
        }

        @Override
        public void run() {
            while (index <= MAX) {
                System.out.println("name: " + name + ", index: " + (index++));
            }
        }
    }

}
